package com.h.web.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.h.common.entity.Cashier;
import com.h.sevice.CashierService;
import com.pandawork.core.exception.SSException;
import com.pandawork.core.log.LogClerk;
import com.pandawork.core.web.spring.controller.Base;

/**
 * 收银员
 * 
 */
@Controller
@RequestMapping(value = "/cashier")
public class CashierController extends Base {

    @Autowired 
    @Qualifier(value = "cashierService")
    private CashierService cashierService;

    @RequestMapping(value = "/toLogin", method = RequestMethod.GET)
    public String toLogin() {
	return "userLogin";
    }

    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String login(@RequestParam String name, @RequestParam String password) {
	Cashier cashier;
	try {
	    cashier = cashierService.findUser(name, password);
	    if (cashier != null) {
		return "redirect:/cashier/begin";
	    }
	} catch (SSException e) {
	    LogClerk.errLog.error(e);
	}
	return "redirect:cashier/toLogin";
    }

    /**
     * 跳转到收银界面
     * 
     * @param model
     * @return
     */
    @RequestMapping(value = "/begin", method = RequestMethod.GET)
    public String toBegin(Model model) {
	Date date = new Date();

	model.addAttribute("date", date);
	// TODO
	return "cashRegister";
    }

}
